using System.Collections.Generic;
using System.Linq;
using MbUnit.Framework;

namespace Tests
{
  public static class Extensions
  {
    public static void ShouldBe<T>(this T input, T targetValue )
    {
      Assert.AreEqual(input, targetValue);
    }


    public static void ShouldBe<T>(this T input, T targetValue, string message)
    {
      Assert.AreEqual(targetValue, input, FormatMessage(message)); // format to look nicer in text report
    }

    public static void ShouldMatchItems<T>(this IEnumerable<T> inputs, IEnumerable<T> values, string message)
    {
      if (inputs == null && values == null)
      {
        return; // if both are null, they match
      }

      if (inputs == null || values == null)
      {
        Assert.Warning("Can't test a null here");
        return;
      }

      if (!inputs.SequenceEqual(values))
      {
        Assert.Warning("Lists are different");
      }
      return;
    }

    private static string FormatMessage(string message)
    {
      return "\"" + message + "\" -";
    }

    private static string FormatMessage(string intro, string message)
    {
      return FormatMessage(string.Format("{0} ({1})", intro, message));
    }
  }
}